package com.www.applyword.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.www.applyword.R;
import com.www.applyword.bean.OrderBean;

/**
 * author : huang
 * date   : 2019/10/21 0021 15:06
 * version: 1.0
 *
 * @author Administrator
 */
public class HotJobAdapter extends CommonRecyclerAdapter<OrderBean> {

    public HotJobAdapter(Context context) {
        super(context, R.layout.item_list_hot_job);
    }



    @Override
    public void onUpdate(BaseAdapterHelper helper, OrderBean item, int position) {
        helper.setText(R.id.tv_Order_PositionName, item.getOrder_PositionName());
        if (item.getOrder_SalaryType() == 0) {
            helper.setText(R.id.tv_Order_Salary, item.getOrder_Salary() + "/时");
            helper.setText(R.id.tv_Order_SalaryType, "时结");
        } else if (item.getOrder_SalaryType() == 1) {
            helper.setText(R.id.tv_Order_Salary, item.getOrder_Salary() + "/日");
            helper.setText(R.id.tv_Order_SalaryType, "日结");
        } else {
            helper.setText(R.id.tv_Order_Salary, item.getOrder_Salary() + "/月");
            helper.setText(R.id.tv_Order_SalaryType, "月结");
        }

        if (!TextUtils.isEmpty(item.getOrder_WorkAddress())) {
            if (item.getOrder_WorkAddress().contains(",")) {
                helper.setText(R.id.tv_Order_WorkAddress, item.getOrder_WorkAddress().split(",")[2]);
            } else {
                helper.setText(R.id.tv_Order_WorkAddress, item.getOrder_WorkAddress().split("-")[2]);
            }
        }
        if (TextUtils.isEmpty((String) item.getOrder_EnterpriseName())){
            helper.setText(R.id.tv_Order_BusinessName, item.getOrder_BusinessName());
        }else {
            helper.setText(R.id.tv_Order_BusinessName, (String)item.getOrder_EnterpriseName());
        }

        if (item.getOrder_PositionType() == 0) {
            helper.setText(R.id.tv_Order_PositionType, "兼职");
        } else {
            helper.setText(R.id.tv_Order_PositionType, "全职");
        }
        if (item.getOrder_Type() == 0) {
            helper.setText(R.id.tv_Order_Type, "只可包揽");
        } else if (item.getOrder_SalaryType() == 1) {
            helper.setText(R.id.tv_Order_Type, "包揽和个人");
        } else {
            helper.setText(R.id.tv_Order_Type, "只可个人");
        }
        if (!TextUtils.isEmpty(item.getOrder_Welfare())) {
            if (!item.getOrder_Welfare().contains(",")) {
                helper.setText(R.id.tv_Order_Welfare, item.getOrder_Welfare());
            } else {
                String mNames[] = item.getOrder_Welfare().split(",");
                for (int i = 0; i < mNames.length; i++) {
                    if (mNames.length < 3) {
                        helper.setText(R.id.tv_Order_Welfare, mNames[0]);
                        helper.getView(R.id.tv_Order_Welfare2).setVisibility(View.VISIBLE);
                        helper.getView(R.id.tv_Order_Welfare3).setVisibility(View.INVISIBLE);
                        // helper.getView(R.id.tv_Order_Welfare3).setVisibility(View.VISIBLE);
                        helper.setText(R.id.tv_Order_Welfare2, mNames[1]);
                        //  helper.setText(R.id.tv_Order_Welfare3, mNames[2]);
                    } else {
                        helper.setText(R.id.tv_Order_Welfare, mNames[0]);
                        helper.getView(R.id.tv_Order_Welfare2).setVisibility(View.VISIBLE);
                        helper.getView(R.id.tv_Order_Welfare3).setVisibility(View.VISIBLE);
                        helper.setText(R.id.tv_Order_Welfare2, mNames[1]);
                        helper.setText(R.id.tv_Order_Welfare3, mNames[2]);
                    }
                }
            }

            //XCFlowLayout view2 = helper.getView(R.id.flowlayout);
            //  ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
            //   ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
            //  lp.leftMargin = 5;
            //   lp.rightMargin = 5;
            //  lp.topMargin = 5;
            //   lp.bottomMargin = 5;
            //  String mNames[] =  item.getOrder_Welfare().split(",");
         /*   for(int i = 0; i < mNames.length; i ++){
                TextView view = new TextView(Utils.getContext());
                view.setText(mNames[i]);
                view.setTextColor(Color.BLACK);
                view2.addView(view,lp);
            }*/
        }
    }
}

